package com.study.concurrent.B_ThreadSynchronizedBasic.b_UseSynchronized;

/**
 * Created by 赵超 on 2017/3/21.
 */
public class Main {
    public static void main(String[] args) {
        /**
         * 创建账户并设置金额
         */
        Account account = new Account();
        account.setBalance(1000);
        /**
         * 创建公司对象
         */
        Company company = new Company(account);
        Thread companyThread = new Thread(company);
        /**
         * 创建银行对象
         */
        Bank bank = new Bank(account);
        Thread bankThread = new Thread(bank);
        System.out.printf("账户：初始金额为 %f\n", account.getBalance());
        /**
         * 使用join()方法等待着两个线程运行完成，然后打印账户余额
         */
        try {
            companyThread.join();
            bankThread.join();
            System.out.printf("账户：最终金额为 %f\n", account.getBalance());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
